package demo;


class Singleton {
    private static Singleton instance = new Singleton();//一加载就实例化对象，称为饿汉
    //用于外部获取饿汉对象
    public static Singleton getInstance() {
        return instance;
    }
    private Singleton() {
        //私有构造方法，外部无法再进实例化
    }
}
public class Test1 {
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        System.out.println(s1 == s2);
    }
}
